<template>
  <div>
    <HeaderInfo :info="activityInfo" @refresh="refresh"></HeaderInfo>
    <div class="disFlxJS gap-20">
      <StatisticsHost :info="activityCount" @setUntrueNum="setUntrueNum" @refresh="refreshCount" />
      <Statisticsticket v-if="activityInfo.maxPrice > 0" :info="activityTicketTotalCount" />
    </div>
    <Statistics v-if="isExistJointly || disabled" :info="activityCount"></Statistics>
    <div class="disFlxJS gap-20">
      <Ranking v-if="orderList.num && orderList.num.length > 1" :list="orderList.num" title="报名数排行（按净报名统计）" valueTitle="报名数" />
      <Ranking v-if="orderList.price && orderList.price.length > 1" :list="orderList.price" title="报名费用排行（按净报名统计）" valueTitle="费用总额" />
    </div>
    <OtherJoinTicketList ref="otherJoinTicketListRef" :isExistJointly="isExistJointly"></OtherJoinTicketList>
    <InvitationRanking ref="invitationRankingRef" :isExistJointly="isExistJointly"></InvitationRanking>
  </div>
</template>

<script>
import HeaderInfo from './HeaderInfo.vue'
import Statistics from './statistics.vue'
import StatisticsHost from './statisticsHost.vue'
import Statisticsticket from './statisticsticket.vue'
import OtherJoinTicketList from './OtherJoinTicketList.vue'
import InvitationRanking from "./InvitationRanking.vue";
import Ranking from './Ranking.vue'
import { activityTypeEnum } from '@/enums/activity'
import {
  getActivityInfo,
  getActivityCountInfo,
  getOrderList,
  setUntrueNum,
  getTicketTotalCountInfo
} from '@/api/activity/activity'
export default {
  components: {
    InvitationRanking,
    HeaderInfo,
    Statistics,
    StatisticsHost,
    Statisticsticket,
    Ranking,
    OtherJoinTicketList
  },
  computed: {
    disabled() {
      return this.activityInfo.activityType === activityTypeEnum.other_join // 协办方
    }
  },
  data() {
    return {
      activityInfo: {},
      activityCount: {},
      activityTicketTotalCount: {},
      orderList: {},
      isExistJointly: false // 判断主办方是否存在协办,
    }
  },

  mounted() {
    this.getActivityDetails()
    this.refreshCount()
  },
  methods: {
    refreshCount() {
      this.getActivityCount()
      this.queryTicketTotalCountInfo()
      this.queryOrderList()
      this.$refs.otherJoinTicketListRef.refresh()
      this.$refs.invitationRankingRef.refresh()
    },
    refresh() {
      this.getActivityDetails()
      this.refreshCount()
    },
    async queryOrderList() {
      const res = await getOrderList(this.$route.query.activityId)
      this.orderList = res.data
    },
    async getActivityDetails() {
      const { activityId } = this.$route.query
      const { data } = await getActivityInfo(activityId)
      this.activityInfo = data
      this.isExistJointly = data.activityCooperateOrgList && data.activityCooperateOrgList.length > 1
    },
    // 获取活动统计
    async getActivityCount() {
      const { activityId } = this.$route.query
      const { data } = await getActivityCountInfo(activityId)
      this.activityCount = data
    },
    async queryTicketTotalCountInfo() {
      const { activityId } = this.$route.query
      const { data } = await getTicketTotalCountInfo(activityId)
      this.activityTicketTotalCount = data
    },
    setUntrueNum(val) {
      setUntrueNum({
        activityId: this.activityInfo.id,
        untruePassedNum: val
      }).then(() => {
        this.$message.success('设置成功')
        this.refreshCount()
      })
    }
  }
}
</script>
